import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: GodK
 * Date: 2024-09-22
 * Time: 11:36
 */
public class Main {
    public static void main45615(String[] a) {
        Scanner in = new Scanner(System.in);
        while(in.hasNext()){
            System.out.print(in.next().toUpperCase().charAt(0));
        }
    }
    public static void mainsfdsfd(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int x = scan.nextInt();
        int[] in = new int[n];
        for(int i = 0;i < n;i++)in[i] = scan.nextInt();
        int left = 0,right = 0,sum = 0,ret = Integer.MAX_VALUE,l = 0,r = 0;
        while(right < n){
            if(sum >= x){
                if(ret > right - left){
                    l = left + 1;
                    r = right + 1;
                    ret = right - left;
                }
                sum -= in[left++];
            }
            if(sum < x)sum += in[right++];
        }
        System.out.print(l);
        System.out.print(' ');
        System.out.print(r);
    }

    public static void main(String[] args) {
        int m = 3;
        int n = 5;
        int size = n;
        int ret = 0;
        int[] in = new int[5010];
        int count = 1;
        int i = 0;
        while(n > 0){
            if(i >= size)i = 0;
            if(count == m && in[i] == 0){
                in[i]--;
                count = 1;
                n--;
            }else if(in[i] != -1){
                count++;
            }
            i++;
        }
        System.out.println(i-1);
    }
}
